
package com.noah.project.dao

import com.noah.project.model.Career
import org.apache.ibatis.annotations.Delete
import org.apache.ibatis.annotations.Insert
import org.apache.ibatis.annotations.Select
import org.apache.ibatis.annotations.Update
import org.springframework.stereotype.Repository

@Repository
interface CareerDao {
    @Insert("INSERT INTO career (coid, aid, title, content, duty, timeStart, timeEnd) " +
            "VALUES(#{coid}, #{aid}, #{title}, #{content}, #{duty}, #{timeStart}, #{timeEnd})")
    fun insert(career: Career): Long

    @Delete("DELETE FROM career WHERE caid = #{caid}")
    fun delete(caid: Long?): Long

    @Delete("DELETE FROM career WHERE aid = #{aid}")
    fun deleteAll(aid: Long?): Long

    @Update("UPDATE career SET " +
            "coid = #{coid}," +
            "title = #{title}," +
            "content = #{content}," +
            "duty = #{duty}," +
            "timeStart = #{timeStart}," +
            "timeEnd = #{timeEnd}" +
            " WHERE caid = #{caid}")
    fun update(company: Career): Long

    @Select("SELECT * FROM career WHERE caid = #{caid}")
    fun findCareer(caid: Long?): Career?

    @Select("SELECT * FROM career WHERE aid = #{aid}")
    fun findCareers(aid: Long?): List<Career>
}
